package com.soft.knowledge.controller;

import com.soft.knowledge.service.TestService;
import com.soft.knowledge.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.*;
import java.util.concurrent.TimeUnit;

/**
 * (Test)表控制层
 *
 * @author makejava
 * @since 2022-11-19 11:10:36
 */
@RestController
@RequestMapping("test")
public class TestController {
    private static final Logger LOG = LoggerFactory.getLogger(UserService.class);
    /**
     * 服务对象
     */
    @Resource
    private TestService testService;

    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping(value = "hello", method = RequestMethod.GET)
    public String hello(String name){
        return "Hello world!";
    }
    @RequestMapping(value = "hello/post", method = RequestMethod.POST)
    public String helloPost(Spring name){
        return "Hello world!"+name;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
//    @GetMapping("selectOne")
//    public Test selectOne(Integer id) {
//        return this.testService.queryById(id);
//    }

    @RequestMapping("/redis/set/{key}/{value}")
    public String set(@PathVariable Long key, @PathVariable String value) {
        redisTemplate.opsForValue().set(key, value, 3600, TimeUnit.SECONDS);
        LOG.info("key: {}, value: {}", key, value);
        return "success";
    }

    @RequestMapping("/redis/get/{key}")
    public Object get(@PathVariable Long key) {
        Object object = redisTemplate.opsForValue().get(key);
        LOG.info("key: {}, value: {}", key, object);
        return object;
    }

}